package com.oraro.paygatewaybiz.module.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.oraro.common.result.Result;
import com.oraro.paygatewaybiz.module.entity.ChannelEntity;
import com.oraro.paygatewaybiz.module.service.ChannelService;
import com.oraro.paygatewaybiz.utils.ValidatorUtils;
import com.oraro.uidgeneratorcore.impl.DefaultUidGenerator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Map;

/**
 * @Author: jianghuiyong
 * @Date: 2018/12/3 9:08
 * @Version 1.0
 */
@RestController
@RequestMapping("/pay/channel")
public class ChannelController {

    @Autowired
    private ChannelService channelService;
    @Autowired
    private DefaultUidGenerator defaultUidGenerator;

    @GetMapping("/queryPage")
    public Result queryPage (Map<String, Object> params) {
        IPage<ChannelEntity> page = channelService.queryPage(params);
        return Result.success().data("page", page);
    }

    @GetMapping("/info/{channelId}")
    public Result channelInfo (@PathVariable Long channelId) {
        ChannelEntity channelEntity = channelService.selectById(channelId);
        return Result.success().data("channel", channelEntity);
    }

    @PostMapping("/save")
    public Result save (@RequestBody ChannelEntity channelEntity) {
        channelEntity.setChannelId(defaultUidGenerator.getUID());
        channelEntity.setDelFlag(0);
        channelEntity.setStatus(1);
        ValidatorUtils.validateEntity(channelEntity);
        channelService.save(channelEntity);
        return Result.success();
    }

    @PostMapping("/update")
    public Result update (@RequestBody ChannelEntity channelEntity) {
        ValidatorUtils.validateEntity(channelEntity);
        channelService.updateById(channelEntity);
        return Result.success();
    }

    @PostMapping("/delete")
    public Result delete (Long[] channelIds) {
        channelService.removeByIds(Arrays.asList(channelIds));
        return Result.success();
    }






}
